class BrowseController < ApplicationController
    include AuthenticatedSystemBrowse
    
    def index
        @districts = District.find(:all)
        @district = @districts[0]
        @communities = Community.paginate_by_district_id @district, :page => 1
        @new_users = User.find(:all, :conditions => ["activated_at IS NOT NULL"], :order => "users.activated_at desc limit 18")
        @posts = CommonPost.paginate :page => params[:page], :include => [:user, :post_category, {:community => :district} ], :order => "replied_at desc"
        @tags = Tag.tags(:limit => 30, :order => "updated_at desc")
        @page_title = "首页"
    end
    
    def groups
        @districts = District.find(:all, :order => 'title desc')
        @district = @districts[0]
        @communities = Community.paginate_by_district_id @district, :page => 1
        @new_users = User.find(:all, :conditions => ["activated_at IS NOT NULL"], :order => "users.activated_at desc limit 18")
        @posts = GroupPost.paginate :page => params[:page], :include => [:user, :group ], :order => "replied_at desc"
        @tags = Tag.tags(:limit => 30, :order => "updated_at desc")
        @page_title = "小组 - 首页"
    end
    
    def sites
        @districts = District.find(:all, :order => 'title desc')
        @district = @districts[0]
        @communities = Community.paginate_by_district_id @district, :page => 1
        @new_users = User.find(:all, :conditions => ["activated_at IS NOT NULL"], :order => "users.activated_at desc limit 18")
        @posts = SitePost.paginate :page => params[:page], :include => [:user, :site ], :order => "replied_at desc"
        @tags = Tag.tags(:limit => 30, :order => "updated_at desc")
        @page_title = "场所 - 首页"
    end
    
    def forums
        @new_users = User.find(:all, :conditions => ["activated_at IS NOT NULL"], :order => "users.activated_at desc limit 18")
        @topics = Topic.paginate :include => [:user, :forum ], :order => "replied_at desc", :page => params[:page]
        @tags = Tag.tags(:limit => 30, :order => "updated_at desc")
        @page_title = "论坛 - 首页"
    end
    
    def users
        #@users_pages, @users = paginate :users, :per_page => 15, :order => "scores desc"
        @users = User.paginate :page => params[:page], :order => "scores desc"
        @page_title = '成员'
    end
    
    def search_users
        @users = User.paginate_search(params[:q], {:page => params[:page]})
    end
    
end
